<?php
ob_start();
session_start();

include("conf/config.php");
include("conf/database.php");
include("conf/tools.php");
$memberId=$_SESSION["member_id"];
$curTime=getIndianDateTime();
$member=getMemberInfo($memberId);
$prgmid=$_REQUEST["prgmid"];
foreach($_POST as $key => $value) { $arr_data[$key]=$value;}

if($prgmid>0){
$memberEventInfo=@array_pop(qry_data("SELECT distinct PM.acc_status,PM.arr_venue,M.registrant_id,M.full_name,P.prg_title  FROM bkitc_profiles M join bkitc_program_members PM on PM.member_id=M.registrant_id JOIN bkitc_programs P ON PM.program_id=P.prg_id WHERE PM.prg_mem_id=$prgmid"));
}

if($_REQUEST["cancel"]==1){

$arr_data["acc_status"]=2;
$arr_data["cancelled_on"]=$curTime;
update_qry("bkitc_program_members",$arr_data,"prg_mem_id=".$prgmid);

sendCancelNotification($memberEventInfo);

header("location:prg_inv_edit.php?prgmid=".$prgmid);

}


$arr_data["arr_time"]=str_pad($arr_data["ahrs"],2,"0",STR_PAD_LEFT).":".str_pad($arr_data["amins"],2,"0",STR_PAD_LEFT)." ".$arr_data["arr_time_sec"];
$arr_data["dep_time"]=str_pad($arr_data["dhrs"],2,"0",STR_PAD_LEFT).":".str_pad($arr_data["dmins"],2,"0",STR_PAD_LEFT)." ".$arr_data["dep_time_sec"];
if($arr_data["acc_status"]==1){
$arr_data["accepted_on"]=$curTime;
}
foreach($arr_data as $key => $value) { $arr_data[$key]=addslashes($value); }

update_qry("bkitc_program_members",$arr_data,"prg_mem_id=".$prgmid);

qry_data("update bkitc_program_members set mem_last_updated='".$curTime."' where prg_mem_id=".$prgmid);


$target_path = "data/permission/";
if(!is_dir($target_path)) mkdir($target_path);
$actual_path=$target_path . $prgmid . "/";
if(!is_dir($actual_path)) mkdir($actual_path);




$arrInfo=array();
if(move_uploaded_file($_FILES['permission_letter']['tmp_name'],$actual_path.$_FILES['permission_letter']['name'])) {

	$arrInfo["permission_letter"]=$_FILES['permission_letter']['name'];
	$arrInfo["permission_letter_on"]=$curTime;
	update_qry("bkitc_program_members",$arrInfo," prg_mem_id=".$prgmid);
	sendPermissionLetterNottification($memberEventInfo);
	//qry_data("update bkitc_program_members set permission_letter_on='".$curTime."' where prg_mem_id=".$prgmid);

} 

if($memberEventInfo["acc_status"]==0 && $arr_data["acc_status"]==1){

sendAcceptNotification($memberEventInfo);

}else{
sendJourneyNotification($memberEventInfo);
}

$arr_data["full_name"]=$member["full_name"];
$arr_data["prg_mem_id"]=$prgmid;

header("location:prg_inv_edit.php?prgmid=".$prgmid);

?>


